package com.borrower.action;

import com.borrower.service.BorrowerService;
import com.borrower.service.BorrowerServiceImpl;
import com.pojo.BookDamageBean;
import com.pojo.BorrowerBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * 提交书籍报损信息
 */
public class BookDamageInfoAction extends Action{
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out = response.getWriter();

//        Long userid = Long.parseLong(request.getParameter("userid"));
        Long bookid = Long.parseLong(request.getParameter("bookid"));
        String bookDamagemsg = request.getParameter("msg");
        String damageDegree = request.getParameter("degree");
        System.out.println(damageDegree);
        HttpSession session=request.getSession();
        String LoginName= (String) session.getAttribute("loginName");
        BorrowerService service = new BorrowerServiceImpl();

        List<BorrowerBean> list=service.UserInfoService(LoginName);
        Long userId= null;
        for(BorrowerBean be:list){
            userId=be.getUserId();
        }
//        System.out.println(userId);
        BookDamageBean bor = new BookDamageBean();
        bor.setUserId(userId);
        bor.setBookId(bookid);
        bor.setBookDamageMsg(bookDamagemsg);
        bor.setDamagedegree(damageDegree);


        if (service.BookDamageInfoService(bor)){
            out.print("提交成功");
        }else {
            out.print("提交失败");
        }

    }
}
